//
//  TGCategory.m
//  ApiStoreSDKDemo
//
//  Created by xalo on 16/2/25.
//  Copyright © 2016年 KessonWu. All rights reserved.
//

#import "TGCategory.h"
#import "SubCategory.h"
@implementation TGCategory

-(void)setValue:(id)value forKey:(NSString *)key
{
    if ([key isEqualToString:@"cat_id"]) {
        
        self.cat_id = [value stringValue];
    }
    
    if ([key isEqualToString:@"cat_name"]) {
        
        self.cat_name = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    
    //遍历二级分类,将其结束存入数组
    if ([key isEqualToString:@"subcategories"]) {
        
        for (NSDictionary *dic in value) {
            
            //二级分类对象
            SubCategory *subcat = [[SubCategory alloc] init];
            
            //字典转模型
            [subcat setValuesForKeysWithDictionary:dic];
            
            //存入数组
            [self.subcats addObject:subcat];
            
        }
        
    }
    
}

-(NSMutableArray *)subcats
{
    if (!_subcats) {
        self.subcats = [NSMutableArray array];
    }
    return _subcats;
}

@end
